function dataReducer(state, action) {
  const newState = { ...state };
  switch (action.type) {
    case 'changeInput':
      newState.inputVal = action.value;
      return newState;
    case 'changeAdd':
      newState.list = [
        ...newState.list,
        { id: state.inputVal, value: state.inputVal }
      ];
      newState.inputVal = '';
      return newState;
    case 'changeDelete':
      newState.list = [...newState.list];
      newState.list.splice(action.value, 1);
      return newState;
    default:
      return state;
  }
}

export default dataReducer;